﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class delete_course_detail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string Cname = Request.QueryString["Cname"];
        Response.Write(" <h1>请确认删除课程'"+ Cname +"'</h1> ");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string Cno = Request.QueryString["Cno"];

        string conn = "Data Source= . ;Initial Catalog=XSXK; User ID=sa; pwd=123";
        SqlConnection connection = new SqlConnection(conn);

        try
        {     
                connection.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection = connection;

                string str_sql = " delete from Course where Cno='"+ Cno +"' ";
                comm.CommandText = str_sql;
                //comm.ExecuteScalar();  //如果为查询语句，则用ExecuteScalar()；否则，用ExecuteNonQuery()
                comm.ExecuteNonQuery();


                Response.Write("<h1>成功删除课程信息！</h1>");
        }

        catch (SqlException ex)
        {
            Response.Write(ex.Message);
        }

        connection.Close();//关闭数据库连接
    }
}